from rest_framework.fields import SerializerMethodField
from rest_framework.serializers import ModelSerializer

from course.models import TeacherModel, CourseModel01


class TeacherSer(ModelSerializer):
    class Meta:
        model = TeacherModel
        fields = '__all__'
class CourseSer(ModelSerializer):
    tea = SerializerMethodField(allow_null=True)
    def get_tea(self,obj):
        return {"name":obj.teacher.name,"job":obj.teacher.job,"intro":obj.teacher.intro,"headimg":obj.teacher.headimg}
    class Meta:
        model = CourseModel01
        fields = '__all__'
